#File Name: FullWDITransparencyIndexConstruct.r
#Author: James Hollyer
#Date: 03/03/2013
#Purpose: To construct a measure of government transparency.  To do this, we
# rely on the reporting or missingness of data from the WDI index.  
#Data Input: IRTprep.dta
#OS: Windows 7

#The following will load the data into R.

library(R2jags)
library(foreign)

setwd("c:/users/james/desktop/dropbox/transparency_and_democracy/transparencyindex/PAReplicationMaterials/Regressions/")

WDIdata<-read.dta("IRTDataforABPRep.dta")
ABPdata<-read.dta("HRVvFracReportedData.dta")

attach(WDIdata)

#The following will prepare a data matrix for export to BUGS.

wdinumber<-WDIdata$countrynum
year<-WDIdata$year
wdinumber2 <- ABPdata$wdinum2
year2 <- ABPdata$year2
newscirc <- ABPdata$newscirc
polity2 <- ABPdata$polity2
rgdpch <- ABPdata$rgdpch
laword <- ABPdata$laword
corrup <- ABPdata$corrup
burqual <- ABPdata$burqual
lag_laword <- ABPdata$lag_laword
lag_corrup <- ABPdata$lag_corrup
lag_burqual <- ABPdata$lag_burqual
frac_reported <- ABPdata$frac_reported


data.frac <- list("polity2", "rgdpch", "laword", "corrup", "burqual", 
"lag_laword", "lag_corrup", "lag_burqual","frac_reported", "newscirc")

parameters.frac <- c("gamma.corrup", "gamma.laword", "gamma.burqual",
"sigma.corrup", "sigma.laword", "sigma.burqual")

results.frac <- jags(data=data.frac, inits=NULL, parameters.frac, model.file="FracReportedABP.txt",
n.chains=2, n.iter=50000, n.burnin=48000)

save.image("FracABPResults.RData")





